/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!				\file		CC_Draw.cc
				\date		june 2010
				\author		TNick

				\brief		Implements CC_Draw class


	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Please read ReadMe.txt and Licence.txt in root folder
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	"../main.h"

#include	<assert.h>

#include	"CC_App.h"

#include	"CC_Item.h"
#include	"CC_Graphic.h"
#include	"CC_Layer.h"
#include	"CC_Block.h"
#include	"CC_Image.h"

#include	<gui/expl/ExplMdl.h>
#include	<gui/var/ErrDlg.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */


/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  DATA    ---------------------------------------------------------------- */


/*  DATA    ================================================================ */
//
//
//
//
/*  FUNCTIONS    ----------------------------------------------------------- */


/* ------------------------------------------------------------------------- */
/* constructor	                                                             */
CC_Draw::CC_Draw()
	: CC_L2DN()
{
	/* no flags set yet */
	uFlg = 0;

	/* selection is not saved */
	pMainSel = NULL;



	/* inform the explorer model about ourselves */
	//ex.SetDrawing(this);

	/* in case of failure, set appropriate flag */
	uFlg |= INIT_FAILED;

}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
/* destructor	                                                             */
CC_Draw::~CC_Draw()
{



}
/* ========================================================================= */


/* ------------------------------------------------------------------------- */
/*                                                                           */
QAbstractItemModel*	CC_Draw::getStdIModel	(void)
{

	int		i;

	/* create a new model */
	ExplModel*	model = new ExplModel(NULL,this);
	if (model == NULL)
		return NULL;

	/* build the tree starting from the top */
	ExplNode *it_GrLay = new ExplNode(
		model, NULL, new QString(TR::tr("Global layers")),
		new QIcon(":/res/tb_img/Group.png"));

		CC_Layer*	pItLy = static_cast<CC_Layer*>(Layers.first());
		for (i = 0; i < Layers.count(); i++)
		{
			///QList<TreeItem*>	pLstLay;


			ExplItem *it_Lay;
			it_Lay = new ExplItem(
				model,
				it_GrLay,
				new QString(pItLy->Name()),
				new QIcon(":/res/tb_img/Layer.png"));

			//if (pItLy->grd->Visible())
			//	it_Lay->setData(2,QIcon(":/res/tb_img/Visible.png"));
			//else
			//	it_Lay->setData(2,QIcon(":/res/tb_img/Invisible.png"));
			//if (pItLy->grd->Printable())
			//	it_Lay->setData(3,QIcon(":/res/tb_img/Print.png"));
			//else
			//	it_Lay->setData(3,QIcon(":/res/tb_img/Inprintable.png"));

			//it_GrLay->appendChild(it_Lay);
			pItLy = static_cast<CC_Layer*>(pItLy->next());
		}

	ExplNode *it_Ref = new ExplNode(
		model, NULL, new QString(TR::tr("References")),
		new QIcon(":/res/tb_img/Group.png"));
	/* TODO */

	ExplNode *it_Spcs = new ExplNode(
		model, NULL, new QString(TR::tr("Spaces")),
		new QIcon(":/res/tb_img/Group.png"));
			ExplItem *it_SpM = new ExplItem(
				model, it_Spcs, new QString(TR::tr("Model")),
				new QIcon(":/res/tb_img/Undo.png"));
		CC_DrawSpace*	pItDs = static_cast<CC_DrawSpace*>(Spaces.first());
		for (i = 0; i < Spaces.count(); i++)
		{
			ExplItem *it_Sp = new ExplItem(
				model, it_Spcs, new QString(pItDs->Name()),
				new QIcon(":/res/tb_img/Undo.png"));
			pItDs = static_cast<CC_DrawSpace*>(pItDs->next());
			Q_UNUSED(it_Sp);
		}

	ExplNode *it_SelSet = new ExplNode(
		model, NULL, new QString(TR::tr("Selection sets")),
		new QIcon(":/res/tb_img/Group.png"));
	/* TODO */

	ExplNode *it_BlkGr = new ExplNode(
		model, NULL, new QString(TR::tr("Block definitions")),
		new QIcon(":/res/tb_img/Group.png"));

		CC_Block*	pItBlk = static_cast<CC_Block*>(Blocks.first());
		for (i = 0; i < Blocks.count(); i++)
		{
			ExplItem *it_Blk = new ExplItem(
				model, it_BlkGr, new QString(pItBlk->Name()),
				new QIcon(":/res/tb_img/Undo.png"));
			pItBlk = static_cast<CC_Block*>(pItBlk->next());
			Q_UNUSED(it_Blk);
		}


	ExplNode *it_RefImg = new ExplNode(
		model, NULL, new QString(TR::tr("Referenced images")),
		new QIcon(":/res/tb_img/Group.png"));

		CC_Image*	pItImg = static_cast<CC_Image*>(Images.first());
		for (i = 0; i < Blocks.count(); i++)
		{
			ExplItem *it_Img = new ExplItem(
				model, it_RefImg, new QString(pItImg->Name()),
				new QIcon(":/res/tb_img/Undo.png"));
			pItImg = static_cast<CC_Image*>(pItImg->next());
			Q_UNUSED(it_Img);
		}


		Q_UNUSED(it_Ref);
		Q_UNUSED(it_SpM);
		Q_UNUSED(it_SelSet);

	return model;
}
/* ========================================================================= */




/* ------------------------------------------------------------------------- */
/* saves the data regarding this class to a stream in CASP_1 format          */
CCERR::EERRORS		CC_Draw::Save_CASP_1	(QDataStream* pStream, CC_Err* pErr)
{
	Q_UNUSED(pStream);
	Q_UNUSED(pErr);
	CCERR::EERRORS		bRet = CCERR::ERR_SUCCESS;


	return bRet;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
/* loads the data regarding this class from a stream in CASP_1 format        */
CCERR::EERRORS		CC_Draw::Load_CASP_1	(QDataStream* pStream, CC_Err* pErr)
{
	Q_UNUSED(pStream);
	Q_UNUSED(pErr);
	CCERR::EERRORS		bRet = CCERR::ERR_SUCCESS;


	return bRet;
}
/* ========================================================================= */


/* ------------------------------------------------------------------------- */
/* saves the data regarding this class to a stream in CASP_1 format          */
CCERR::EERRORS		CC_Draw::Save_DXF	(QDataStream* pStream, CC_Err* pErr)
{
	Q_UNUSED(pStream);
	Q_UNUSED(pErr);
	CCERR::EERRORS		bRet = CCERR::ERR_SUCCESS;


	return bRet;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
/* loads the data regarding this class from a stream in CASP_1 format        */
CCERR::EERRORS		CC_Draw::Load_DXF	(QDataStream* pStream, CC_Err* pErr)
{
	Q_UNUSED(pStream);
	Q_UNUSED(pErr);
	CCERR::EERRORS		bRet = CCERR::ERR_SUCCESS;


	return bRet;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
/* savers a file                                                             */
CCERR::EERRORS	CC_Draw::Save	(QString pPthName, CC_Err* pErr, FILEFORM Format)
{
	Q_UNUSED(pPthName);
	Q_UNUSED(pErr);
	Q_UNUSED(Format);

	CCERR::EERRORS		bRet = CCERR::ERR_SUCCESS;

	return bRet;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
/* loads a file                                                              */
CCERR::EERRORS	CC_Draw::Load	(QString pPthName, CC_Err* pErr, FILEFORM Format)
{
	Q_UNUSED(pPthName);
	Q_UNUSED(pErr);
	Q_UNUSED(Format);

	CCERR::EERRORS		bRet = CCERR::ERR_SUCCESS;

	return bRet;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
/* initialize new drawing with a set of predefined values                    */
CCERR::EERRORS	CC_Draw::performNew	(CC_Err* pErr)
{
	Q_UNUSED(pErr);

	CCERR::EERRORS		bRet = CCERR::ERR_SUCCESS;

	/* this, actually, shall be the standard initialization; this shall be
	placed under appropriate conditiopn once settings layout is decided */

	if (!SUCCEDED(CC_Layer::create(this,NULL,QString(),NULL,pErr)))
		{
		pErr->Add(CCERR::EERR, CCERR::CTX_DRAWINT,
				  TR::tr("Create new drawing: failed to add default layer."));
		return CCERR::ERR_STATUS;
		}


	return bRet;
}
/* ========================================================================= */

/*  FUNCTIONS    =========================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
